package com.cv4j.app.fragment;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

import com.cv4j.app.ResourceTable;
import com.cv4j.app.ability.BeautySkinAbility;
import com.cv4j.app.ability.ColorFilterAbility;
import com.cv4j.app.ability.PaintAility;
import com.cv4j.app.ability.CompositeFilersAbility;
import com.cv4j.app.ability.DslAbility;
import com.cv4j.app.ability.GaussianBlurAbility;
import com.cv4j.app.ability.GridViewFilterAbility;
import com.cv4j.app.ability.SelectFilterAbility;
import com.cv4j.app.app.BaseFragment;
import com.cv4j.app.utils.JumpUtil;

/**
 * FiltersFragment
 *
 * @since 2021-05-14
 */
public class FiltersFragment extends BaseFragment implements Component.ClickedListener {
    private Text text1;
    private Text text2;
    private Text text3;
    private Text text4;
    private Text text5;
    private Text text6;
    private Text text7;
    private Text text8;
    private Text text9;
    private Context context;

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component root = scatter.parse(ResourceTable.Layout_fragment_filters, container, false);
        context = root.getContext();
        initView(root);
        return root;
    }

    private void initView(Component root) {
        text1 = (Text)root.findComponentById(ResourceTable.Id_text1);
        text1.setClickedListener(this);
        text2 = (Text)root.findComponentById(ResourceTable.Id_text2);
        text2.setClickedListener(this);
        text3 = (Text)root.findComponentById(ResourceTable.Id_text3);
        text3.setClickedListener(this);
        text4 = (Text)root.findComponentById(ResourceTable.Id_text4);
        text4.setClickedListener(this);
        text5 = (Text)root.findComponentById(ResourceTable.Id_text5);
        text5.setClickedListener(this);
        text6 = (Text)root.findComponentById(ResourceTable.Id_text6);
        text6.setClickedListener(this);
        text7 = (Text)root.findComponentById(ResourceTable.Id_text7);
        text7.setClickedListener(this);
        text8 = (Text)root.findComponentById(ResourceTable.Id_text8);
        text8.setClickedListener(this);
        text9 = (Text)root.findComponentById(ResourceTable.Id_text9);
        text9.setClickedListener(this);
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()){
            case ResourceTable.Id_text1: // 选择滤镜
                JumpUtil.jumpToAbility(context, SelectFilterAbility.class,(Text) component);
                break;
            case ResourceTable.Id_text2: // 组合滤镜
                JumpUtil.jumpToAbility(context, CompositeFilersAbility.class,(Text) component);
                break;
            case ResourceTable.Id_text3: // Rxjava来操作滤镜
                JumpUtil.jumpToAbility(context, DslAbility.class,(Text) component);
                break;
            case ResourceTable.Id_text4: // 基于DSL方式实现滤镜(只适用于Kotlin)
                JumpUtil.jumpToAbility(context, DslAbility.class,text4);
                break;
            case ResourceTable.Id_text5: // 显示多个滤镜的效果
                JumpUtil.jumpToAbility(context, GridViewFilterAbility.class,text5);
                break;
            case ResourceTable.Id_text6: // 彩色滤镜效果
                JumpUtil.jumpToAbility(context, ColorFilterAbility.class,text6);
                break;
            case ResourceTable.Id_text7: // 高斯模糊
                JumpUtil.jumpToAbility(context, GaussianBlurAbility.class,text7);
                break;
            case ResourceTable.Id_text8: // 人脸磨皮
                JumpUtil.jumpToAbility(context, BeautySkinAbility.class,text8);
                break;
            case ResourceTable.Id_text9: // 画风效果
                JumpUtil.jumpToAbility(context, PaintAility.class,text9);
                break;
            default:
                break;
        }
    }
}
